package cn.javabb.log.action;

import cn.javabb.core.entity.sys.LogDO;
import cn.javabb.log.action.base.BaseActionMap;
import cn.javabb.log.action.base.ResetLog;
import cn.javabb.log.action.model.SystemMethod;

/**
 * @desc: 系统异常日志行为
 * @author: javabb (javabob(a)163.com)
 * @create: 2019/11/03 23:40
 */
public class SystemAction extends BaseActionMap {

    public static final String RUNTIME_EXCEPTION = "runtime_exception";
    @Override
    public void init() {
        // 系统异常行为
        putMethod(RUNTIME_EXCEPTION, new SystemMethod("系统异常","runtimeException"));
    }
    /**
     * 系统异常行为方法
     */
    public void runtimeException(ResetLog resetLog){
        RuntimeException runtime = (RuntimeException) resetLog.getParam("e");
        StringBuilder message = new StringBuilder();
        message.append(runtime.toString());
        StackTraceElement[] stackTrace = runtime.getStackTrace();
        for (StackTraceElement stack : stackTrace) {
            message.append("\n\t").append(stack.toString());
        }
        LogDO logDO = resetLog.getLog();
        logDO.setOperName("系统");
        logDO.setMessage(String.valueOf(message));
    }
}
